Skip to content

Preserve state on hot reload#3896

Open
T4rk1n wants to merge 1 commit into
devfrom
state-preserving-hot-reload
Open

Preserve state on hot reload#3896
T4rk1n wants to merge 1 commit into
devfrom
state-preserving-hot-reload

Conversation

@T4rk1n

@T4rk1n T4rk1n commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Add dev_tools_hot_reload_preserve_state: keep UI state across hot reloads

When enabled, the renderer records UI-driven prop edits, set_props
updates (clientside, serverside and websocket) and memory-type dcc.Store
writes as [newVal, originalVal] pairs. Just before a hot reload - soft
RELOAD dispatch or full page reload - they are snapshotted (in memory +
sessionStorage), then re-applied to the incoming layout unless a prop's
initial value changed in the reloaded code, in which case the new code
wins. Unmatched edits stay pending so components inserted by callbacks
(e.g. pages content) are restored too. The snapshot is only written when
a hot reload fires and consumed on use, so a manual browser refresh
still resets the app.

Off by default; enable with dev_tools_hot_reload_preserve_state=True or
DASH_HOT_RELOAD_PRESERVE_STATE=true.

…oads

When enabled, the renderer records UI-driven prop edits, set_props
updates (clientside, serverside and websocket) and memory-type dcc.Store
writes as [newVal, originalVal] pairs. Just before a hot reload - soft
RELOAD dispatch or full page reload - they are snapshotted (in memory +
sessionStorage), then re-applied to the incoming layout unless a prop's
initial value changed in the reloaded code, in which case the new code
wins. Unmatched edits stay pending so components inserted by callbacks
(e.g. pages content) are restored too. The snapshot is only written when
a hot reload fires and consumed on use, so a manual browser refresh
still resets the app.

Off by default; enable with dev_tools_hot_reload_preserve_state=True or
DASH_HOT_RELOAD_PRESERVE_STATE=true.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@BSd3v

BSd3v commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

I dont know if this would be worth it or if people would be interested, but could expand this to keep the current state of executed callbacks for seeing in the callback graphs.

@KoolADE85

Copy link
Copy Markdown
Contributor

This is a cool feature, I will find this useful in my own work!
Can we distinguish between "reloading the same app" and "starting a completely different app"?
If you are working on "App A" locally (http://localhost:8050) and you switch to "App B" which happens to share a common callback:

@callback(Input("clear", "n_clicks"))
def clear(n_clicks):
    if not n_clicks:
        raise PreventUpdate

    # does something benign in App A
    # does something destructive in App B

then clicking the button in App A, will cause a problem in App B.
And it wouldn't be obvious that the source of the "bug" came from a button click in App A.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants